import shutil
import os
import cityhash

def pre_hash(input_file,filename):
    # a.txt
    # b.txt
    # a.bin
    # b.bin
    base_dir = os.path.dirname(os.path.abspath(__file__)).replace("\\", "/") + "/../"

    output_file = base_dir+ "data/"
    if filename == "a":
        output_file = output_file + "client/a"
    else:
        output_file = output_file + "server/b"

    shutil.copy(input_file, output_file+".txt")
    # subprocess.run([base_dir+"/bin/cityhash128", output_file+".txt" , output_file+".bin"], capture_output=True, text=True)
    with open(output_file+".bin", "wb") as fout:
        with open(output_file+".txt", "rb") as fin:
            for line in fin:
                hash_value = cityhash.CityHash128(line)
                fout.write(hash_value.to_bytes(16, byteorder='big'))
